package com.auemall.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.auemall.dao.AttributeValuesMapper;
import com.auemall.dao.ProductAttributeMapper;
import com.auemall.po.AttributeValues;
import com.auemall.po.ProductAttribute;
import com.auemall.service.ProductAttributeService;

@Service
public class ProductAttributeServiceImpl implements ProductAttributeService {

	
	@Autowired
	private ProductAttributeMapper productAttributeMapper;
	
	
	@Autowired
	private AttributeValuesMapper attributeValuesMapper;

	@Override
	public List<AttributeValues> findAllAttributeByPid(Integer pid) {

		//通过产品id查询出对应的属性
		List<ProductAttribute> list = productAttributeMapper.findAllAttributeValuesByProductId(pid);
		
		List<Integer> valuesList = new ArrayList<Integer>();
		
		for (ProductAttribute attr:list) {
			
			valuesList.add(attr.getValueId());
			
		}
		
		if (valuesList.size() == 0) {
			
			valuesList.add(0);
		}
		
		return attributeValuesMapper.findAllAttributeValuesByCategoryId(valuesList);
	}
	

}
